package com.meet.controller;

import com.meet.bizservice.StatisticsService;
import com.meet.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import java.util.Arrays;

@RestController
@RequestMapping("/statistics")
@CrossOrigin
@Validated
public class MeetStatisticsController {

    @Autowired
    private StatisticsService statisticsService;

    @GetMapping("/user-participation")
    public Result<?> getUserParticipationStats() {
        return statisticsService.getUserParticipationStats();
    }

    @GetMapping("/activity-trend")
    public Result<?> getActivityTrendStats(@RequestParam(defaultValue = "week") @NotBlank String timePeriod) {
        // 验证时间周期参数
        if (!Arrays.asList("week", "month", "quarter", "year").contains(timePeriod)) {
            return Result.error(400, "无效的时间周期参数", "INVALID_TIME_PERIOD");
        }
        return statisticsService.getActivityTrendStats(timePeriod);
    }
}
